﻿using System.Collections.Generic;
using System.Linq;
using CommonLib;
using WordStat.Tasks;
using WordStat.WordExceptions;

namespace WordStat.Anylize
{
    public sealed class PageService
    {
        public void InitService()
        {
            var container = new WordExceptionService();
            container.Load();
            SetWordExceptions(container.WordExceptions);
        }

        public bool IsToDelete(string word)
        {
            if (string.IsNullOrEmpty(word))
                return true;

            if (word.Length == 1)
                return true;

            if (word.Contains("&nbsp"))
                return true;

            if (word.Contains("&quot"))
                return true;

            {
                int res;
                if (int.TryParse(word, out res))
                    return true;
            }

            if (_wordExceptions.Any(w => w == word))
                return true;

            return false;
        }

        public void SetWordExceptions(List<string> wordExceptions)
        {
            _wordExceptions = wordExceptions;
        }

        private List<string> _wordExceptions;
    }
}
